package com.heima.wemedia.controller;


import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dto.WmLoginDto;
import com.heima.model.wemedia.entity.WmUser;
import com.heima.wemedia.service.WmUserService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 自媒体用户表(WmUser)表控制层
 *
 * @author makejava
 * @since 2022-04-09 15:28:46
 */
@RestController
@RequestMapping("login")
public class WmUserLoginController {
    /**
     * 服务对象
     */
    @Resource
    private WmUserService wmUserService;

    /**
     * 分页查询
     *
     * @param wmUser 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<WmUser>> queryByPage(WmUser wmUser, PageRequest pageRequest) {
        return ResponseEntity.ok(this.wmUserService.queryByPage(wmUser, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<WmUser> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.wmUserService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param wmUser 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<WmUser> add(WmUser wmUser) {
        return ResponseEntity.ok(this.wmUserService.insert(wmUser));
    }

    /**
     * 编辑数据
     *
     * @param wmUser 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<WmUser> edit(WmUser wmUser) {
        return ResponseEntity.ok(this.wmUserService.update(wmUser));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.wmUserService.deleteById(id));
    }

    /**
     * 自媒体用户登录
     *
     * @param dto
     * @return
     */
    @PostMapping("/in")
    public ResponseResult login(@RequestBody WmLoginDto dto) {
        return wmUserService.login(dto);
    }



}

